package kr.saeildamil.androidstudy.ch11;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;

public class RadioCheck extends Activity {
	TextView tv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch11_radiocheck);

		tv = (TextView) findViewById(R.id.ch11_radiocheck_tv);

		RadioGroup radiogroup = (RadioGroup) findViewById(R.id.ch11_radiocheck_colorgroup);
		CheckBox chkBox = (CheckBox) findViewById(R.id.ch11_radiocheck_chkwhiteback);
		ToggleButton tgbtn = (ToggleButton) findViewById(R.id.ch11_radiocheck_tglanguage);

		radiogroup.setOnCheckedChangeListener(mlistener);
		chkBox.setOnCheckedChangeListener(listener);
		tgbtn.setOnCheckedChangeListener(listener);
	}

	RadioGroup.OnCheckedChangeListener mlistener = new RadioGroup.OnCheckedChangeListener() {

		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			if (group.getId() == R.id.ch11_radiocheck_colorgroup) {
				switch (checkedId) {
				case R.id.ch11_radiocheck_rared:
					tv.setTextColor(Color.RED);
					break;
				case R.id.ch11_radiocheck_ragreen:
					tv.setTextColor(Color.GREEN);
					break;
				case R.id.ch11_radiocheck_rablue:
					tv.setTextColor(Color.BLUE);
					break;
				}
			}

		}
	};

	CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			if (buttonView.getId() == R.id.ch11_radiocheck_chkwhiteback) {
				if (isChecked) {
					tv.setBackgroundColor(Color.WHITE);
				} else {
					tv.setBackgroundColor(Color.TRANSPARENT);
				}
			}
			if (buttonView.getId() == R.id.ch11_radiocheck_tglanguage) {
				if (isChecked) {
					tv.setText("샘플");
				} else {
					tv.setText("Sample");
				}
			}
		}
	};
}
